// 获取本地存储的值
const user = JSON.parse(localStorage.getItem('user') as string)
console.log(user)

const initState = user || {
	userInfo: {
		nickname: '',
		tel: '',
		email: '',
		avator: '',
		role: '',
		token: '',
	},
	isLogin: false
}


const userReducer = (state = initState, action: any) => {
	switch (action.type) {
		case 'loginSuccess': {
			return {
				isLogin: true,
				userInfo: action.payload
			}
		}
		case 'quitLogin': {
			return {
				userInfo: {
					nickname: '',
					tel: '',
					email: '',
					avator: '',
					role: '',
					token: '',
				},
				isLogin: false
			}
		}
		default: return state
	}
}

export default userReducer